package com.mzy.designMode.adapter;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author mzy
 * @Date 2022/5/30 7:52
 * @Version 1.0
 */

/**
 * 简单适配器模式
 * https://www.bilibili.com/video/BV1DA4y1f7sY?spm_id_from=333.337.search-card.all.click
 */
public class AdapterPattern {
    public static void main(String[] args) {
        String translate = new Adapter(new Speaker()).translate();
        System.out.println(translate);
    }
}

class Speaker {
    public String speak() {
        return "China is NB";
    }
}
    interface Translator {
        public String translate();
    }

    class Adapter implements Translator {

        // 间接关联
        private Speaker speaker;

        public Adapter(Speaker speaker) {
            this.speaker = speaker;
        }

        @Override
        public String translate() {
            String speak = speaker.speak();
            return speak;
        }
    }
